import os, sys
from Configuration import Configuration
from Util import *;
import time;
def newDir(path):
    if os.path.exists(path):
        return True
    else :
        os.mkdir(path)
        return True
    return False

def copyClientFile(clients):
    expId = Configuration.getId()
    file = os.open("temp.sh", "w")
    for client in clients:
        cmd = "scp -i ~/.ssh/sqid sq@" + client + ":~/OpenTTDTesting/trunk/%d"%expId + "*" + " ." 
        print cmd
        print >> file, cmd
    os.system("sh temp.sh")

#def copyFiles(sourceDir, targetDir):  
#    for f in os.listdir(sourceDir):  
#        sourceF = os.path.join(sourceDir, f)  
#        targetF = os.path.join(targetDir, f)
#        if os.path.isfile(sourceF):  
#            if not os.path.exists(targetDir):  
#                os.makedirs(targetDir)  
#            if not os.path.exists(targetF) or (os.path.exists(targetF) and (os.path.getsize(targetF) != os.path.getsize(sourceF))):  
#                open(targetF, "wb").write(open(sourceF, "rb").read())           
#        if os.path.isdir(sourceF):  
#            copyFiles(sourceF, targetF)
            
def removeDir(path):
    if(sys.platform == "win32"):
        os.system('rd /S /Q ' + toWinFile(path));
    if(sys.platform.find("linux")>=0): 
        os.system("rm -fr " + toLinux(path));
 